package com.cyzy.controller;

import com.cyzy.dto.Result;
import com.cyzy.pojo.*;
import com.cyzy.service.MainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Comparator;
import java.util.List;

/**
 * @author zxw
 * @create 2025-05-26 下午4:06
 */
@RestController
@RequestMapping("/main")
public class MainController {
    @Autowired
    private MainService mainService;
    /**
     * 获取栏目列表
     */
    @GetMapping("/getColumnList")
    public Result getColumnList(@RequestParam("campusId") String campusId) {
        List<Column> list = mainService.getColumnList(campusId);
        if(list == null){
            Result.error().message("获取栏目信息失败");
        }
        // 确保按columnSort升序排序
        list.sort(Comparator.comparingLong(Column::getColumnSort));
        return Result.ok().data("list",list);
    }

    @GetMapping("/getActivity")
    public Result getActivity(@RequestParam("campusId") String campusId){
        System.out.println("查询活动" + campusId);
        List<Activity> list = mainService.selectActivity(campusId);
        return Result.ok().data("list",list);
    }

    @GetMapping("/getCourse")
    public Result getCourse(@RequestParam("campusId") String campusId){

        List<Course> list = mainService.selectCourse(campusId);
        return Result.ok().data("list",list);
    }

    @GetMapping("/getSeckill")
    public Result getSeckill(@RequestParam("campusId") String campusId){
        System.out.println("查询秒杀" + campusId);
        List<Seckill> list = mainService.selectSeckill(campusId);
        return Result.ok().data("list",list);
    }

    @GetMapping("/getBanner")
    public Result getBanner(@RequestParam("campusId") String campusId){
        List<Banner> list = mainService.selectBanner(campusId);
        System.out.println(list + "2222222222222222222222222222222222222222");
        return Result.ok().data("list",list);
    }
}
